<template>
  <div>
    <el-container>
      <el-header style="background-color: #02c0ff; display: flex; align-items: center; justify-content: space-between; margin-top: -50px">
        <!-- 左边部分 -->
        <div style="font-size: 30px; font-family: 华文行楷">东莞人民医疗管理系统</div>

        <div style="text-align: right; margin-right: 100px">
          <el-dropdown @command="handleCommand">
            <span class="el-dropdown-link">
               欢迎您：{{ name }}<i style="font-size: 18px" class="el-icon-arrow-down el-icon-right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="updatePassWord">修改密码</el-dropdown-item>
              <el-dropdown-item command="logout">退出登录</el-dropdown-item>
              <el-dropdown-item command="selectUser">查看个人资料</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </el-header>

      <el-container>
        <el-aside width="200px">
          <el-menu class="el-menu-vertical-demo" @select="changeMenu">
            <el-submenu index="1">
              <template slot="title">
                <i class="el-icon-location"></i>
                <span>用户模块</span>
              </template>

              <el-menu-item index="/UserInfo">用户管理</el-menu-item>
              <el-menu-item index="/RoleInfo">权限管理</el-menu-item>
            </el-submenu>

            <el-submenu index="2">
              <template slot="title">
                <i class="el-icon-location"></i>
                  <span>信息管理</span>
              </template>
              <el-menu-item index="2-1">挂号管理</el-menu-item>
              <el-menu-item index="2-2">医生管理</el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>

        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import axios from "axios";
export default {
  name: "Home",
  data(){
    return {
      name: ""
    }
  },
  mounted() {
    let uid = this.$route.query.uid;
    console.log("========="+uid);
    this.loginUser(uid);
  },
  methods: {
    changeMenu(index, indexPath) {
      this.$router.push(index);
    },
    handleCommand(type) {
      if(type == "updatePassWord") {
        alert("修改密码");
      } else if(type == "logout") {
        this.$router.push("/login");
      } else if(type == "logout") {
        alert("2");
      }
    },
    loginUser(uid) {
      axios.get("http://localhost:8002/user/loginUser", {
        params: {
          "uid": uid
        }
      }).then(res => {
        console.log(JSON.stringify(res.data.data));
        this.name = res.data.data.name;
      }).catch(err => {
        console.log(JSON.stringify(err));
      })
    }
  }
}
</script>

<style scoped></style>
